/**
 * 
 */
package com.jushu.storbox.database;

//import com.huawei.sharedrive.util.DataBaseContext;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

/**
 * DAOFactory.instance(context).getFileDao(); IFolderDao folderDao =
 * DAOFactory.instance(context).getFolderDao();
 * 
 */
public class DAOFactory {
	private static DBHelper dbHelper = null;

	private static DAOFactory instance = new DAOFactory();

	private static SQLiteDatabase db = null;

	private IFolderDao folderDao = null;

	private IFileDao fileDao = null;
	
	private IAlbumDao albumDao = null;

	private IShareFileDao shareFileDao = null;

	private IShareFolderDao shareFolderDao = null;

	private IShareINodeDao shareINodeDao = null;
	
	private IEnterpriseAddressDao enterpriseAddressDao = null;
	
	private IUploadFileDao uploadFileDao = null;
	
	private IDownloadFileDao downloadFileDao = null;
	
	private ITeamSpaceDao teamSpaceDao=null;
	
	private ITeamSpaceMemberDao teamSpaceMemberDao=null;

	private ITeamSpaceFolderDao teamSpaceFolderDao = null;
	
	private ITeamSpaceFileDao teamSpaceFileDao = null;

	private IPreUploadDao preUploadDao = null;
	
	private IAlbumFolderDao albumFolderDao = null;
	
	private IUserDao userDao = null;
	
	private DAOFactory() {
	}

	public static DAOFactory instance(Context context) {
		if (dbHelper == null) {
			dbHelper = DBHelper.getInstance(context);
			db = dbHelper.getWritableDatabase();
		}
		return instance;
	}

	public void closeDb() {
		if(db != null){
			db.close();
		}
	}

	/**
	 * @return
	 */
	public IFolderDao getFolderDao() {
		if (folderDao == null) {
			folderDao = new FolderDao();
			folderDao.setDb(db);
		}
		return folderDao;
	}

	/**
	 * @return
	 */
	public IFileDao getFileDao() {
		if (fileDao == null) {
			fileDao = new FileDao();
		}
		fileDao.setDb(db);
		return fileDao;
	}
	
	/**
	 * @return
	 */
	public IAlbumDao getAlbumDao() {
		if (albumDao == null) {
			albumDao = new AlbumDao();
		}
		albumDao.setDb(db);
		return albumDao;
	}

	/**
	 * @return
	 */
	public IShareFileDao getShareFileDao() {
		if (shareFileDao == null) {
			shareFileDao = new ShareFileDao();
		}
		shareFileDao.setDb(db);
		return shareFileDao;
	}

	/**
	 * @return
	 */
	public IShareFolderDao getShareFolderDao() {
		if (shareFolderDao == null) {
			shareFolderDao = new ShareFolderDao();
		}
		shareFolderDao.setDb(db);
		return shareFolderDao;
	}

	/**
	 * @return
	 */
	public IShareINodeDao getShareINodeDao() {
		if (shareINodeDao == null) {
			shareINodeDao = new ShareINodeDao();
		}
		shareINodeDao.setDb(db);
		return shareINodeDao;
	}
	public IEnterpriseAddressDao getEnterpriseAddressDao() {
		if (enterpriseAddressDao == null) {
			enterpriseAddressDao = new EnterpriseAddressDao();
		}
		enterpriseAddressDao.setDb(db);
		return enterpriseAddressDao;
	}
	public IDownloadFileDao getDownloadFileDao() {
		if (downloadFileDao == null) {
			downloadFileDao = new DownloadFileDao();
		}
		downloadFileDao.setDb(db);
		return downloadFileDao;
	}
	public IUploadFileDao getUploadFileDao() {
		if (uploadFileDao == null) {
			uploadFileDao = new UploadFileDao();
		}
		uploadFileDao.setDb(db);
		return uploadFileDao;
	}
	
	public ITeamSpaceDao getTeamSpaceDao(){
		if(teamSpaceDao ==null){
			teamSpaceDao = new TeamSpaceDao();
		}
		teamSpaceDao.setDb(db);
		return teamSpaceDao;
	}
	
	public ITeamSpaceMemberDao getTeamSpaceMemberDao(){
		if(teamSpaceMemberDao ==null){
			teamSpaceMemberDao = new TeamSpaceMemberDao();
		}
		teamSpaceMemberDao.setDb(db);
		return teamSpaceMemberDao;
	}
	
	public IPreUploadDao getPreUploadDao() {
		if(preUploadDao ==null){
			preUploadDao = new PreUploadDao();
		}
		preUploadDao.setDb(db);
		return preUploadDao;
	}

	public IAlbumFolderDao getAlbumFolderDao() {
		if(albumFolderDao == null) {
			albumFolderDao = new AlbumFolderDao();
		}
		albumFolderDao.setDb(db);
		return albumFolderDao;
	}
	
	public IUserDao getUserDao() {
		if(userDao == null) {
			userDao = new UserDao();
		}
		userDao.setDb(db);
		return userDao;
	}
	
}
